# -*_ codeing=utf-8 -*-
# @Time: 2024/11/8 10:57
# @Author: foxhuty
# @File: main.py
# @Software: PyCharm
# @Based on python 3.13
from gaokao_data_process import GaokaoData2025, GaokaoDataProcess, GaokaoDataSeniorOne, ExamRoom, GetInfoFromId, \
    JuniorExam, ExamInvigilators, CatalogueCourses, ContrastExams
import sys
from gaokao_logging import MyException
import os


def show_menu(file):
    """
    Displays a menu for the user to select different data processing options.

    Args:
        file (str): The path to the input file.

    Returns:
        None
    """
    while True:
        # Prompt the user to select a data processing option
        flag = eval(input(f'请按数字键选择您所需数据处理类别:\n '
                          f'    1:年级考试成绩分析；\n '
                          f'    2:高一全科类考试成绩分析；\n'
                          f'     3:区级以上考试成绩分析；\n'
                          f'     4:考室安排；\n'
                          f'     5:获取身份信息；\n'
                          f'     6:初中成绩统计分析；\n'
                          f'     7:监考安排表；\n'
                          f'     8:分类汇总表；\n'
                          f'     9:生成与上次考试对比成绩表；\n'
                          f'     10:按其它数字键退出程序.\n请选择：'))

        if flag == 1:
            # Prompt the user to input the line ratio for physics and history classes
            GaokaoData2025.physics_line_ratio = float(input('请输入物理类划线比例(用小数表示): '))
            GaokaoData2025.history_line_ratio = float(input('请输入历史类划线比例(用小数表示): '))
            # Set the flag for score assignment method
            GaokaoData2025.flag_score_added = True
            # Create an instance of GaokaoData2025 for school exam data processing
            school_exam = GaokaoData2025(file)
            print(f'{school_exam.__str__()}文件数据正在处理中'.center(106, '*'))
            # Process the school exam data
            school_exam.excel_school_files()
            # Handle exceptions
            MyException(school_exam)
            print(
                f'{school_exam.__str__()}文件数据处理完成，excel数据表已生成在{os.path.dirname(school_exam.file)}文件夹中'.center(
                    106, '*'))
            break
        elif flag == 2:
            # Prompt the user to input the line ratio for senior one students
            GaokaoDataSeniorOne.line_ratio = float(input('请输入划线比例(用小数表示): '))
            # Set the flag for score assignment method
            GaokaoData2025.flag_score_added = True
            # Create an instance of GaokaoDataSeniorOne for senior one exam data processing
            senior_one = GaokaoDataSeniorOne(file)
            print(f'{senior_one.__str__()}文件数据正在处理中'.center(106, '*'))
            # Process the senior one exam data
            senior_one.excel_school_senior_one_files()
            # Handle exceptions
            MyException(senior_one)
            print(
                f'{senior_one.__str__()}文件数据处理完成，excel数据表已生成在{os.path.dirname(senior_one.file)}文件夹中'.center(
                    106, '*'))
            break
        elif flag == 3:
            # Create an instance of GaokaoDataProcess for city exam data processing
            city_exam = GaokaoDataProcess(file)
            print(f'{city_exam.__str__()}文件数据正在处理中'.center(106, '*'))
            # Process the city exam data
            city_exam.excel_files()
            # Handle exceptions
            MyException(city_exam)
            print(
                f'{city_exam.__str__()}文件数据处理完成，excel数据表已生成在{os.path.dirname(city_exam.file)}文件夹中'.center(
                    106, '*'))
            break
        elif flag == 4:
            # Prompt the user to input the number of students in each exam room
            ExamRoom.num_in_room = int(input('请输入考室人数：'))
            # Create an instance of ExamRoom for exam room arrangement
            exam_room = ExamRoom(file)
            print(f'{exam_room.__str__()}文件数据正在处理中'.center(106, '*'))
            # Arrange the exam rooms
            exam_room.exam_room_choice()
            # Handle exceptions
            MyException(exam_room)
            print(
                f'{exam_room.__str__()}文件数据处理完成，excel数据表已生成在{GaokaoData2025.output_dir}文件夹中'.center(
                    106, '*'))
            break
        elif flag == 5:
            # Create an instance of GetInfoFromId to get identity information
            id_info = GetInfoFromId(file)
            print(f'{id_info.__str__()}文件数据正在处理中'.center(106, '*'))
            # Handle exceptions
            MyException(id_info)
            # Get sex, birth, and age information
            id_info.get_sex_birth_age()
            print(f'{id_info.__str__()}文件数据处理完成，excel数据表已生成在{GaokaoData2025.output_dir}文件夹中'.center(
                106, '*'))
            break
        elif flag == 6:
            # Prompt the user to input the passing score for junior high school exams
            JuniorExam.good_total = float(input('请输入划线分数：'))
            # Create an instance of JuniorExam for junior high school exam data processing
            junior_exam = JuniorExam(file)
            print(f'{junior_exam.__str__()}文件数据正在处理中'.center(106, '*'))
            # Handle exceptions
            MyException(junior_exam)
            # Concatenate the exam results
            junior_exam.concat_results()
            print(
                f'{junior_exam.__str__()}文件数据处理完成，excel数据表已生成在{GaokaoData2025.output_dir}文件夹中'.center(
                    106, '*'))
            break
        elif flag == 7:
            # Prompt the user to input the number of exam subjects and rooms
            ExamInvigilators.exam_numbers = int(input('请输入考试科目数：'))
            ExamInvigilators.room_numbers = int(input('请输入考室间数：'))
            # Create an instance of ExamInvigilators for invigilator arrangement
            invigilators = ExamInvigilators(file)
            print(f'{invigilators.__str__()}文件数据正在处理中'.center(106, '*'))
            # Handle exceptions
            MyException(invigilators)
            # Arrange the invigilators
            invigilators.exam_teachers()
            print(
                f'{invigilators.__str__()}文件数据处理完成，excel数据表已生成在{GaokaoData2025.output_dir}文件夹中'.center(
                    106, '*'))
            break
        elif flag == 8:
            # Create an instance of CatalogueCourses for course cataloging
            catalogue_courses = CatalogueCourses(file)
            print(f'{catalogue_courses.__str__()}文件数据正在处理中'.center(106, '*'))
            # Handle exceptions
            MyException(catalogue_courses)
            # Split the courses by subject
            catalogue_courses.split_by_subject()
            print(
                f'{catalogue_courses.__str__()}文件数据处理完成，excel数据表已生成在{GaokaoData2025.output_dir}文件夹中'.center(
                    106, '*'))
            break
        elif flag == 9:
            # Prompt the user to input the names of the current and previous exams
            exam_1 = input('请输入本次考试名称：')
            exam_2 = input('请输入对比考试名称：')
            # Create an instance of ContrastExams to compare exam results
            exams_contrasted = ContrastExams(path_this=path_one, path_last=path_two)
            print(f'{exams_contrasted.__str__()}文件数据正在处理中'.center(106, '*'))
            # Handle exceptions
            MyException(exams_contrasted)
            # Compare the exam results
            exams_contrasted.create_excel_file(exam_1, exam_2)
            print(
                f'{exams_contrasted.__str__()}文件数据处理完成，excel数据表已生成在D:\\成绩统计结果\\文件夹中'.center(
                    106, '*'))
            break


@GaokaoData2025.time_use
def main():
    """
    The main function of the program, responsible for calling the show_menu function to display the menu.

    This function attempts to call the show_menu function and passes the file_path variable as a parameter.
    If an exception occurs during the execution of the show_menu function, it will catch the exception
    and print the error message to the standard error output.

    Args:
        None

    Returns:
        None
    """
    try:
        # Call the show_menu function, passing the file path as a parameter
        show_menu(file_path)
    except Exception as e:
        # If an exception occurs, print the error message to the standard error output
        print(f"An error occurred: {e}", file=sys.stderr)


if __name__ == '__main__':
    file_path = r'D:\data_test_files\高三半期考试成绩年级.xlsx'
    # file_path = r'D:\data_test_files\高2023级上期末考试成绩数据.xlsx'
    # file_path = r'D:\data_test_files\高2023级高三上期末成绩数据.xlsx'
    # file_path = r'D:\data_test_files\lq_总成绩表_物理类_历史类.xlsx'
    # file_path = r'D:\data_test_files\高2023级高二上赋分期末成绩数据.xlsx'

    # file_path = r'D:\data_test_files\学生成绩汇总（成都十一中高2024级半期考试）.xlsx'

    # file_path = r'D:\data_test_files\高2022级零诊成绩测试数据.xlsx'
    # file_path = r'D:\data_test\高三半期考试成绩年级.xlsx'
    # file_path = r'D:\data_test_files\高2015级学生信息.xlsx'
    # file_path = r'D:\data_test_files\高2021级艺术类学生原始表.xlsx'
    # file_path = r'D:\data_test_files\监考老师名单.xlsx'

    # file_path = r'D:\data_test_files\高2022级零诊成绩测试数据.xlsx'
    # file_path = r'D:\data_test_files\初中\八年级上半期成绩.xlsx'
    # file_path = r'D:\data_test\高三半期考试成绩年级.xlsx'

    path_one = file_path
    path_two = r'D:\data_test_files\高三半期考试成绩年级.xlsx'

    # 物理类各科有效分
    GaokaoDataProcess.subjects_good_scores_physics = {'语文': 100, '数学': 94, '英语': 91, '物理': 58, '政治': 63,
                                                      '地理': 56, '化学': 50, '生物': 55, '总分': 480}
    # 历史类各科有效分
    GaokaoDataProcess.subjects_good_scores_history = {'语文': 99, '数学': 74, '英语': 85, '历史': 71, '政治': 63,
                                                      '地理': 55, '生物': 60, '总分': 465}
    # ExamRoom.num_in_room = 35
    # ExamInvigilators.exam_numbers = 6
    # ExamInvigilators.room_numbers = 9

    # 运行主程序
    main()
